<html>
<head><meta charset="utf-8"><title>Can the compiler allocate reserved registers? · project-inline-asm · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/index.html">project-inline-asm</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html">Can the compiler allocate reserved registers?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="202258687"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202258687" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Amanieu <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202258687">(Jun 28 2020 at 22:35)</a>:</h4>
<p>An interesting question came up in <a href="https://github.com/rust-lang/rust/issues/73450#issuecomment-650463347">this comment</a>. We currently ban the frame pointer from being used as an operand because LLVM will miscompile if the function happens to need a frame pointer. However if the function does <em>not</em> need a frame pointer then LLVM might choose to use the frame pointer for a <code>reg</code> operand. This can lead to some code being subtly wrong as shown in the linked comment.</p>



<a name="202259956"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202259956" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202259956">(Jun 28 2020 at 23:12)</a>:</h4>
<p>I would ultimately call this a bug in LLVM, frame pointer is not something that must be preserved throughout the function I think</p>



<a name="202259964"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202259964" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202259964">(Jun 28 2020 at 23:12)</a>:</h4>
<p>some approaches to unwinding could rely on it…  I guess.</p>



<a name="202259975"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202259975" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202259975">(Jun 28 2020 at 23:13)</a>:</h4>
<p>but that’s a platform-specific, or even a project-specific concern, not something that should be enforced globally.</p>



<a name="202260039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202260039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nagisa <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202260039">(Jun 28 2020 at 23:15)</a>:</h4>
<p>maybe there's some other reason I don’t know about, though.</p>



<a name="202347069"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202347069" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202347069">(Jun 29 2020 at 18:03)</a>:</h4>
<p>So, there's an interesting similarity between this and vector registers.</p>



<a name="202347160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202347160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202347160">(Jun 29 2020 at 18:04)</a>:</h4>
<p>There are environments where you cannot safely use any of the vector registers, such as because you're in an OS kernel and userspace is using them.</p>



<a name="202347257"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/216763-project-inline-asm/topic/Can%20the%20compiler%20allocate%20reserved%20registers%3F/near/202347257" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/216763-project-inline-asm/topic/Can.20the.20compiler.20allocate.20reserved.20registers.3F.html#202347257">(Jun 29 2020 at 18:05)</a>:</h4>
<p>But you may be able to use vector registers and vector instructions in a function that carefully arranges to be able to do so.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>